package com.wechatapp.mengyao.poetry.vo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.Id;

/**
 * @author yanghuaxu
 * @date 2025/5/27 12:04
 */
@Data
@Document(indexName = "chinese_poetry")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ChinesePoetryESView {

    @Id
    @Field(name = "id", type = FieldType.Keyword)
    @JsonProperty("id")
    private Integer id;

    @Field(name = "author", type = FieldType.Keyword)
    @JsonProperty("author")
    private String author;

    @Field(name = "author_id", type = FieldType.Long)
    @JsonProperty("author_id")
    private Integer authorId;

    @Field(name = "dynasty", type = FieldType.Keyword)
    @JsonProperty("dynasty")
    private String dynasty;

    @Field(name = "title", type = FieldType.Text, analyzer = "ik_analyzer")
    @JsonProperty("title")
    private String title;

    @Field(name = "rhythmic", type = FieldType.Text)
    @JsonProperty("rhythmic")
    private String rhythmic;

    @Field(name = "chapter", type = FieldType.Text)
    @JsonProperty("chapter")
    private String chapter;

    @Field(name = "collection", type = FieldType.Text)
    @JsonProperty("collection")
    private String collection;

    @Field(name = "comment", type = FieldType.Text)
    @JsonProperty("comment")
    private String comment;

    @Field(name = "content", type = FieldType.Text, analyzer = "ik_analyzer")
    @JsonProperty("content")
    private String content;

    @Field(name = "notes", type = FieldType.Text)
    @JsonProperty("notes")
    private String notes;

    @Field(name = "section", type = FieldType.Text)
    @JsonProperty("section")
    private String section;

    @Field(name = "translation", type = FieldType.Text)
    @JsonProperty("translation")
    private String translation;

    @Field(name = "tags", type = FieldType.Keyword)
    @JsonProperty("tags")
    private String tags;

    public ChinesePoetryPageView convert2Page() {
        ChinesePoetryPageView p = new ChinesePoetryPageView();
        p.setId(this.id);
        p.setAuthorId(this.authorId);
        p.setAuthor(this.author);
        p.setCollection(this.collection);
        p.setDynasty(this.dynasty);
        p.setTitle(this.title);
        p.setContentString(this.content);
        return p;
    }

}
